package com.study.spring.queue;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

@Component
public class SpringMQProduct {

    @Autowired
    JmsTemplate jmsTemplate;

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("SpringTopicMQ.xml");
        SpringMQProduct springMQProduct = (SpringMQProduct)context.getBean("springMQProduct");

        springMQProduct.jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage("spring 整合mq 发送消息");
                return message;
            }
        });


    }



}
